﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyStackMvc.Models
{
    public class MyStackRepository
    {
        MyStackDataClassesDataContext db = new MyStackDataClassesDataContext();

        public IQueryable<Story> GetAllStories()
        {
            return db.Stories;
        }

        public Story GetStoryById(int id)
        {
            return db.Stories.SingleOrDefault<Story>(story => story.StoryId == id);
        }

        internal int PushStory(int userId, string title, string content)
        {
            Story story = new Story();
            story.Title = title;
            story.Content = content;
            
            // TODO: author id

            db.Stories.InsertOnSubmit(story);
            db.SubmitChanges();


            return story.StoryId;
        }
    }
}
